package com.BMS.DAOImpl;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.BMS.DAO.ManagerDao;
import com.BMS.entity.Manager;

/**
 * 管理员实体类DAO层接口实现类
 * @author lenovo
 *
 */
@Repository("ManagerDaoImpl")
public class ManagerDaoImpl implements ManagerDao {

	@Resource
	private SessionFactory sessionFactory;
	
	private Session getSession() {
		return sessionFactory.getCurrentSession();
	}
	
	// add
	@Override
	public void addManager(Manager manager) {
		this.getSession().save(manager);
	}

	// delete
	@Override
	public void deleteManagerById(String manager_id) {
		this.getSession().createQuery("delete Manager where manager_ID=?").setParameter(0, manager_id).executeUpdate();
	}

	// find
	@Override
	public Manager findManagerById(String manager_id) {
		return (Manager) this.getSession().createQuery("from Manager where manager_ID=?").setParameter(0, manager_id).uniqueResult();
	}

	// update
	@Override
	public void updateManager(Manager manager) {
		this.getSession().update(manager);
	}

}
